package stat;

import tsd.TSD;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

/**
 * Author: Oleg Yasnev (oyasnev@gmail.com)
 * Date: 23.05.14
 */
public class TSDStat extends Observable {

    public List<TSD> tsdList; // filtered tsd list
    protected List<TSD> sourceTsdList;

    public TSDStat(List<TSD> tsdList) {
        sourceTsdList = tsdList;
        this.tsdList = tsdList;
        setChanged();
    }

    public void filter(String s) {
        s = "(?i).*" + s + ".*"; // turn on case insensitivity and "substring mode"
        tsdList = new ArrayList<TSD>();
        for (TSD tsd : sourceTsdList) {
            if (tsd.repeat.name.matches(s) || tsd.repeat.cls.matches(s)) {
                tsdList.add(tsd);
            }
        }
        setChanged();
    }
}
